package ysomap.exploits.rmi.component;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import java.io.IOException;
import java.net.Socket;
import java.rmi.server.RMIClientSocketFactory;

/**
 * @author wh1t3P1g
 * @since 2020/2/25
 */
public class RMISSLClientSocketFactory implements RMIClientSocketFactory {
    public Socket createSocket(String host, int port) throws IOException {
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            ctx.init(null, new TrustManager[] {new TrustAllSSL()}, null);
            SSLSocketFactory factory = ctx.getSocketFactory();
            return factory.createSocket(host, port);
        } catch(Exception e) {
            throw new IOException(e);
        }
    }
}
